package net.zoneland.knowledge.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import com.branchitech.account.ldap.UserBean;
import com.branchitech.gum.domain.Organization;
import com.google.common.collect.Lists;

import net.zoneland.knowledge.enums.CmpDnEnum;
import net.zoneland.knowledge.enums.QaBankCmpDnEnum;
import net.zoneland.knowledge.exceptions.UserServiceException;
import net.zoneland.knowledge.model.LoginUserPojo;
import net.zoneland.knowledge.service.UserService;

/**
 * Uom实现.
 *
 * @author: bcc
 *     2022/3/11
 */
@ConditionalOnProperty(name = "biz.user-service", havingValue = "mock")
@Service
public class UserServiceServiceMock extends AbstractUserService  {


    @Override
    public LoginUserPojo getUserByUid(final String uid) {
        final LoginUserPojo userPojo=new LoginUserPojo();
        userPojo.setUserID(uid);
        userPojo.setUserName("方正");
        userPojo.setEmail("cjfz@zj.chinamobile.com");
        userPojo.setMobilePhone("13622221111");
        userPojo.setDepartmentDN("OU=兰德,OU=信息技术部,OU=合作伙伴,O=zmcc");
        userPojo.setDeptName("兰德");
        userPojo.setCompanyDN("OU=hzzmcc,O=zmcc");
        userPojo.setCompanyName("省公司");
        userPojo.setAdminOrgDn("OU=兰德,OU=信息技术部,OU=合作伙伴,O=zmcc");
        userPojo.setAdminOrgName("兰德");
        userPojo.setUserIdCard("cjfz");
        return userPojo;
    }

    @Override
    public String getCityId(final LoginUserPojo user) {

        return CmpDnEnum.getCityByValue(user.getCompanyDN());
    }

    @Override
    public List<Organization> queryBranchCompList(boolean includeCommon) throws UserServiceException {
        final QaBankCmpDnEnum[] enums = QaBankCmpDnEnum.values();
        List<Organization> rs = new ArrayList<>();
        for(QaBankCmpDnEnum company: enums) {
            if(!includeCommon) {
                if (company == QaBankCmpDnEnum.COMMON) {
                    continue;
                }
            }
            Organization o = new Organization();
            o.setOrgCode(company.getValue());
            o.setOrgName(company.getName());
            rs.add(o);
        }
        return rs;
    }

    @Override
    public List<Organization> queryDeptByCompCode(final String companyCode) throws UserServiceException {
        return null;
    }

    @Override
    public boolean checkUserExists(final String userName, final String orgCode) throws UserServiceException {
        return true;
    }

    @Override
    public Organization getCompanyByCode(final String code) throws UserServiceException {
        return queryBranchCompList(true).stream()
            .filter(item -> code.equals(item.getOrgCode())).findFirst().orElse(null);
    }

    @Override
    public Organization getCompanyByName(final String orgName) throws UserServiceException {
        return queryBranchCompList(true).stream()
            .filter(item -> orgName.equals(item.getOrgName())).findFirst().orElse(null);
    }

    @Override
    public List<String> getUserDeptCodeAndParentDeptCode(final LoginUserPojo loginUserPojo) throws UserServiceException {
        return Lists.newArrayList("OU=兰德,OU=信息技术部,OU=合作伙伴,O=zmcc",
                                  "OU=信息技术部,OU=合作伙伴,O=zmcc",
                                  "OU=合作伙伴,O=zmcc");
    }

}
